package com.ch.web.controller;

import com.ch.web.entity.XyScEntity;
import com.ch.web.service.XyScService;
import com.ch.web.utils.PageUtils;
import com.ch.web.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;


/**
 * @author chenHao
 * @email 1429542285@qq.com
 * @date 2022-10-20 14:14:44
 */
@RestController
@RequestMapping("xy/sc")
public class XyScController {
    @Autowired
    private XyScService xyScService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = xyScService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{talkId}")

    public R info(@PathVariable("talkId") Long talkId) {
        XyScEntity xySc = xyScService.getById(talkId);

        return R.ok().put("xySc", xySc);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody XyScEntity xySc) {
        xyScService.save(xySc);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody XyScEntity xySc) {
        xyScService.updateById(xySc);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] talkIds) {
        xyScService.removeByIds(Arrays.asList(talkIds));

        return R.ok();
    }

    /**
     * 收藏说说
     */
    @PostMapping("/scTalk")
    public R scTalk(@RequestBody XyScEntity xyScEntity, HttpServletRequest request) {
        return R.okOrError(xyScService.scTalk(xyScEntity, request));
    }
    /**
     * 取消收藏
     */
    @PostMapping("/cancelScTalk")
    public R cancelScTalk(@RequestBody XyScEntity xyScEntity, HttpServletRequest request) {
        return R.okOrError(xyScService.cancelScTalk(xyScEntity, request));
    }
}
